import { Injectable, } from "@nestjs/common";
import { ModuleRef } from "@nestjs/core";
import { AsyncConfig } from "src/providers/async.config";
import { ASYNC_CONFIG_KEY } from "src/constant/provider.const";
import { UsersService } from "src/business/users/users.service";
import { UserDto } from "src/business/users/interfaces/user.dto";

@Injectable()
export class ModuleRefService {
    constructor(private moduleRef: ModuleRef) { }

    getUsers(): Promise<UserDto[]> {
        const userService = this.moduleRef.get<UsersService>(UsersService, { strict: false });
        return userService.findAllSelectFields();
    }

    async getConfigProvider(): Promise<AsyncConfig> {
        console.info("Use Custom Provider AsyncConfig from ModuleRef");
        const appConfig = await this.moduleRef.get(ASYNC_CONFIG_KEY,{ strict: false });
        return appConfig;
    }
}
